var path = require('path')
var webpack = require('webpack')
var autoprefixer = require('autoprefixer')
var precss       = require('precss')
var ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'dist/static/'),
    filename: 'bundle.js',
    publicPath: '/static/'
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    //https://webpack.github.io/docs/stylesheets.html
    // /css/bundle.css前面有斜线就是绝对路径
    new ExtractTextPlugin("css/bundle.css", {
         allChunks: true
    })
  ],
  module: {
    loaders: [
       {
        test: /\.js$/,
        loader: 'babel',
        exclude: /node_modules/,
        query: {
          cacheDirectory: true,
          presets: ['react', 'es2015']
        },
        include: __dirname
      },
      {
        test:   /\.css$/,
        //loader: "style-loader!css-loader!postcss-loader"
        loader: ExtractTextPlugin.extract("style-loader","css-loader!postcss-loader"),
        //include: __dirname
      },
      //mac需要下面才能解析图片,linux不需要
      { 
         test: /\.(png|jpg|gif)$/, 
         loader: 'file-loader'
      } 
      //{test: /\.(png|jpg|gif)$/, loader: 'file-loader?name=img/[name].[ext]'} 
    ]
  },
  postcss: function () {
     return [autoprefixer, precss];
  }
}